package com.platform.service.impl;

import com.platform.dao.StudyDao;
import com.platform.entity.StudyCategoryEntity;
import com.platform.entity.StudyEntity;
import com.platform.service.StudyCategoryService;
import com.platform.service.StudyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Service实现类
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2018-08-21 17:19:56
 */
@Service("studyService")
public class StudyServiceImpl implements StudyService {
    @Autowired
    private StudyDao studyDao;
    @Autowired
    private StudyCategoryService studyCategoryService;

    @Override
    public StudyEntity queryObject(Integer id) {
        return studyDao.queryObject(id);
    }

    @Override
    public List<StudyEntity> queryList(Map<String, Object> map) {
        return studyDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return studyDao.queryTotal(map);
    }

    @Override
    public int save(StudyEntity study) {
        StudyCategoryEntity cate = studyCategoryService.queryObject(study.getType());
        study.setTypeName(cate.getName());
        return studyDao.save(study);
    }

    @Override
    public int update(StudyEntity study) {
            StudyCategoryEntity cate = studyCategoryService.queryObject(study.getType());
            study.setTypeName(cate.getName());
            //study.setImageUrl(cate.getImageUrl());
        return studyDao.update(study);
    }

    @Override
    public int delete(Integer id) {
        return studyDao.delete(id);
    }

    @Override
    public int deleteBatch(Integer[] ids) {
        return studyDao.deleteBatch(ids);
    }
}
